package com.mobilezu.mobile.pushserver.xmpp.presence;

import org.xmpp.packet.Presence;

import com.mobilezu.mobile.pushserver.model.PushUser;
import com.mobilezu.mobile.pushserver.xmpp.session.ClientSession;
import com.mobilezu.mobile.pushserver.xmpp.session.SessionManager;

public class PresenceManager {

	private SessionManager sessionManager;

	/**
	 * ������.
	 */
	public PresenceManager() {
		sessionManager = SessionManager.getInstance();
	}

	/**
	 * �ж��û��Ƿ����.
	 * 
	 * @param user
	 *            the user
	 * @return true if the user is available
	 */
	public boolean isAvailable(PushUser user) {
		return sessionManager.getSession(user.getUsername()) != null;
	}

	/**
	 * ���ص�ǰ���ߵ��û�
	 * 
	 * @param user
	 *            the user
	 * @return the current presence of the user.
	 */
	public Presence getPresence(PushUser user) {
		if (user == null) {
			return null;
		}
		Presence presence = null;
		ClientSession session = sessionManager.getSession(user.getUsername());
		if (session != null) {
			presence = session.getPresence();
		}
		return presence;
	}

}
